package expo43client;

import java.net.*;
import java.io.*;

/**
 *
 * @author TommySprat
 */
public class Expo43ClientScoreServer extends Thread {

    ServerSocket serverSocket;
    Socket clientSocket;
    PrintWriter out;
    String inputLine, outputLine;

    @Override
    public void run() {
        serverSocket = null;
        try {
            serverSocket = new ServerSocket(4445);
        } catch (IOException e) {
            System.err.println("Could not listen on port: 4445.");
            System.exit(1);
        }

        clientSocket = null;
        try {
            //Waits until a client connects on serverSocket
            clientSocket = serverSocket.accept();
            System.out.println("ScoreClient connected");
        } catch (IOException e) {
            System.err.println("Accept failed.");
            System.exit(1);
        }

        try {
            out = new PrintWriter(clientSocket.getOutputStream(), true);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(
                    clientSocket.getInputStream()));
        } catch (IOException exc) {
            System.out.println("Error during ClientScoreServer IO");
            exc.printStackTrace();
        }

        out.println("Welcome e43ClientScoreServerClient");

        while (true) {
            try {
                sleep(10);
            } catch (InterruptedException exc) {
                System.out.println("Interrupted o.O");
            }

        }
    }

    public void setVisible(boolean visibility) {
        if (visibility == true) {
            out.println("true");
        } else {
            out.println("false");
        }
    }

    public void startScoreboard() {
        out.println("startscore");
    }

    public void stopScoreboard() {
        out.println("stopscore");
    }
}
